<form class="form-inline" method="get">

    <div class="form-group col-xs-2"  style="width: 20%;">
        <div class="col-xs-12">
            <input class="form-control" name="id" value="{$id}"
                   placeholder="商品ID">
        </div>
    </div>

    <div class="form-group col-xs-2"  style="width: 20%;">
        <div class="col-xs-12">
            <input class="form-control" name="title" value="{$title}"
                   placeholder="商品名称">
        </div>
    </div>
    <div class="form-group col-xs-2">
        <select id="brand-selector" name="brand_id" class="form-control" tabindex="-1">
            <option value="">选择品牌</option>
            {foreach $brand as $k=>$b}
            <option value="{$k}" {if condition="$k != '' && $k==$brand_id"}selected{/if} >{$b}</option>
            {/foreach}
        </select>
    </div>
    <div class="form-group col-xs-2">
        <select id="is-presell-selector" name="is_presell" class="form-control" tabindex="-1">
            <option value=""></option>
            <option value="1" {if condition="$is_presell != '' && $is_presell==1"}selected{/if} >预售</option>
            <option value="0" {if condition="$is_presell != '' && $is_presell==0"}selected{/if} >不是预售</option>
        </select>
    </div>
    <br>
    <hr>
    {include file="public/categorySelector" one-name="category_id1" two-name="category_id2" three-name="category_id3" /}
    <hr>
    <div class="form-group col-xs-2">
        <select id="status-selector" name="status" class="form-control" tabindex="-1">
            <option value="">
                无选择
            </option>
            <option value="1" {if condition="$status != '' && $status==1"}selected{/if} >上架</option>
            <option value="0" {if condition="$status != '' && $status==0"}selected{/if} >下架</option>
        </select>
    </div>

    <div class="form-group col-xs-3">
        <button type="submit" class="btn btn-success">
            搜索
        </button>

        <button type="button" class="btn btn-primary" onclick="modal('{:url(\'add\')}','添加商品')">
            添加商品
        </button>
    </div>
</form>

<hr>

<table class="table table-striped">
    <thead>
    <tr>
        <td>ID</td>
        <td>排序</td>
        <td>商品名称</td>
        <td>所属分类</td>
        <td>所属品牌</td>
        <td>是否预售</td>
        <td>预售区</td>
        <td>缩略图</td>
        <td>价格</td>
        <td>库存</td>
        <td>销量</td>
        <td>浏览</td>
        <!--<td>分享次数</td>-->
        <td>热卖推荐</td>
        <td>上下架</td>
        <td>创建时间<br>更新时间</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    {volist name="list" id="item"}
    <tr>
        <td>{$item.id}</td>
        <td>{$item.display_order}</td>
        <td>{$item.title}</td>
        <td>{$item.c1_title|get_visible_title=$item.c1_visible} - {$item.c2_title|get_visible_title=$item.c2_visible}</td>
        <td>{$brand[$item.brand_id]}</td>
        <td>
            {if $item.is_presell eq 1}
            <label class="label label-success">预售</label>
            {else}
            <label class="label label-success">不是预售</label>
            {/if}
        </td>
        <td>
            <label class="label label-success">{:isset($presell[$item.presell_id])?$presell[$item.presell_id]:'普通商品'}</label>
        </td>
        <td>
            <a href="javascript:void(0);" onclick="ejectImg('{$item.img_url}','商品{$item.title}logo');">
                <img style="width: 100px;" src="{$item.img_url}" />
            </a>
        </td>
        <td>￥{$item.price}</td>
        <td>{$item.stock}</td>
        <td>{$item.sales_nums}</td>
        <td>{$item.view_nums}</td>
        <!--<td>{$item.shares}</td>-->
        <td>
            {if $item["is_index"]}
            <label class="label label-success" data-toggle="ajaxSwitch" data-switch-status="1" style="cursor: pointer;"
                   data-switch-value-0="1|推荐|label label-success|{:url('isIndex',array('id'=>$item['id'],'status'=>1))}"
                   data-switch-value-1="0|不推荐|label label-danger|{:url('isIndex',array('id'=>$item['id'],'status'=>0))}">推荐</label>
            {else}
            <label class="label label-danger" data-toggle="ajaxSwitch" data-switch-status="0" style="cursor: pointer;"
                   data-switch-value-0="1|推荐|label label-success|{:url('isIndex',array('id'=>$item['id'],'status'=>1))}"
                   data-switch-value-1="0|不推荐|label label-danger|{:url('isIndex',array('id'=>$item['id'],'status'=>0))}">不推荐</label>
            {/if}
        </td>
        <td>
            {if $item["status"]}
            <label class="label label-success" data-toggle="ajaxSwitch" data-switch-status="1" style="cursor: pointer;"
                   data-switch-value-0="1|上架|label label-success|{:url('status',array('id'=>$item['id'],'status'=>1))}"
                   data-switch-value-1="0|下架|label label-danger|{:url('status',array('id'=>$item['id'],'status'=>0))}">上架</label>
            {else}
            <label class="label label-danger" data-toggle="ajaxSwitch" data-switch-status="0" style="cursor: pointer;"
                   data-switch-value-0="1|上架|label label-success|{:url('status',array('id'=>$item['id'],'status'=>1))}"
                   data-switch-value-1="0|下架|label label-danger|{:url('status',array('id'=>$item['id'],'status'=>0))}">下架</label>
            {/if}
        </td>
        <td>
            <p>{$item.create_time|show_datetime}</p>
            <p>{$item.update_time|show_datetime}</p>
        </td>
        <td>

            <div class="btn-group">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    操作
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li>
                        <a href="javascript:void(0)" onclick="modal('{:url(\'edit\',array(\'id\'=>$item[\'id\']))}', '编辑商品')">
                            编辑
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)" data-toggle="confirm"
                           data-title="删除商品"
                           data-content="确认删除商品？删除后不可恢复，请谨慎操作！"
                           data-url="{:url('remove',array('id'=>$item['id']))}">
                            删除
                        </a>
                    </li>

                    <li role="separator" class="divider"></li>
                </ul>
            </div>
        </td>
    </tr>
    {/volist}
    </tbody>
</table>

<div class="row">
    <div class="col-xs-12" style="text-align: right;">
        {$list->render()}
    </div>
</div>

<script src="__PUBLIC__/vendors/select2/js/select2.min.js"></script>
<script type="application/javascript">
    $(function () {
        // $("#is-group-selector").select2({
        //     placeholder: "选择是否拼团",
        //     allowClear: true
        // });
        $("#is-presell-selector").select2({
            placeholder: "选择是否预售",
            allowClear: true
        });
        $("#status-selector").select2({
            placeholder: "选择上下架",
            allowClear: true
        });
        $("#is-pass-selector").select2({
            placeholder: "选择是否审核",
            allowClear: true
        });
        $("#brand-selector").select2({
            placeholder: "选择商品品牌",
            allowClear: true
        });

    });
</script>